package com.blrs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.core.page.PageDomain;
import com.blrs.common.core.page.TableSupport;
import com.blrs.common.utils.page.PaginationUtil;
import com.blrs.domain.CostControl;
import com.blrs.domain.ExternalDocument;
import com.blrs.domain.vo.BusinessMainClassVo;
import com.blrs.service.project.costcontrol.ICostControlService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 成本管理Controller
 *
 * @author yuxiang.chen
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/control/control")
public class CostControlController extends BaseController
{
    @Autowired
    private ICostControlService costControlService;


    //修改主分类
    @PostMapping("/editMainClass")
    public AjaxResult editMainClass(@RequestBody BusinessMainClassVo businessMainClassVo) {
        return toAjax(costControlService.editMainClass(businessMainClassVo));
    }
    /**
     * 查询成本管理列表
     */
    //@PreAuthorize("@ss.hasPermi('control:control:list')")
    @GetMapping("/list")
    public TableDataInfo list(CostControl costControl)
    {
        startPage();
        List<CostControl> list = costControlService.selectCostControlList(costControl);
        return getDataTable(list);
    }

    /**
     * 导出成本管理列表
     */
    //@PreAuthorize("@ss.hasPermi('control:control:export')")
    @Log(title = "成本管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CostControl costControl)
    {
        List<CostControl> list = costControlService.selectCostControlList(costControl);
        ExcelUtil<CostControl> util = new ExcelUtil<CostControl>(CostControl.class);
        util.exportExcel(response, list, "成本管理数据");
    }

    /**
     * 获取成本管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('control:control:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(costControlService.selectCostControlById(id));
    }

    /**
     * 新增成本管理
     */
    //@PreAuthorize("@ss.hasPermi('control:control:add')")
    @Log(title = "成本管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CostControl costControl)
    {
        return toAjax(costControlService.insertCostControl(costControl));
    }

    /**
     * 修改成本管理
     */
    //@PreAuthorize("@ss.hasPermi('control:control:edit')")
    @Log(title = "成本管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CostControl costControl)
    {
        return toAjax(costControlService.updateCostControl(costControl));
    }

    /**
     * 删除成本管理
     */
    //@PreAuthorize("@ss.hasPermi('control:control:remove')")
    @Log(title = "成本管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(costControlService.deleteCostControlByIds(ids));
    }
}
